﻿using System.Collections.Generic;

namespace Comsenz.Services.Blocks.Configs
{
    /// <summary>
    /// 模块参数字段
    /// </summary>
    /// <author>Chiron</author>
    public class BlockGetSetting
    {
        #region Ctors
        /// <summary>
        /// 构建参数字段
        /// </summary>
        public BlockGetSetting()
        {
        }
        /// <summary>
        /// 构建参数字段
        /// </summary>
        /// <param name="title">显示的名称</param>
        /// <param name="type">表单类型</param>
        /// <param name="defaultValue">默认值</param>
        /// <param name="values">可选值</param>
        public BlockGetSetting(string title, InputType type = InputType.text, object defaultValue = null, SettingValues values = null)
        {
            Title = title;
            Type = type;
            Default = defaultValue;
            Values = values;
        }
        #endregion Ctors
        /// <summary>
        /// 显示的名称
        /// </summary>
        public string Title { get; set; }
        /// <summary>
        /// 表单类型
        /// </summary>
        public InputType Type { get; set; }
        /// <summary>
        /// 默认值
        /// </summary>
        public object Default { get; set; }
        /// <summary>
        /// 可供选择的值
        /// </summary>
        public SettingValues Values { get; set; }

        /// <summary>
        /// 取得配置值
        /// </summary>
        /// <returns></returns>
        public Dictionary<object, object> GetConfigValue()
        {
            var value = new Dictionary<object, object>();
            if (Values != null)
            {
                for (var i = 0; i < Values.Count; i++)
                {
                    value.Add(i, Values[i].GetConfigValue());
                }
            }
            return new Dictionary<object, object>
            {
                {"title",Title},
                {"type",Type},
                {"value",value},
                {"default",Default}
            };
        }

    }
}
